/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ar.com.gruposicom.view.utils;

import ar.com.gruposicom.controller.AnalizerController;
import ar.com.gruposicom.controller.OperationController;
import ar.com.gruposicom.domain.Command;
import ar.com.gruposicom.domain.Politic;
import ar.com.gruposicom.domain.Result;
import ar.com.gruposicom.domain.TrueValue;
import java.util.ArrayList;
import java.util.Collection;
import javax.swing.JTable;
import javax.swing.JTextArea;

/**
 *
 * @author marcelo
 */
public class UIAddCommandUtils 
{
    private UIAddOperationUtils utilsOperation;
    private Collection<Command> comands = new ArrayList<>();
    private Collection<TrueValue> values = new ArrayList<>();
    private Collection<Politic> politics = new ArrayList<>();
    private Command command;
    private Politic politic;
    

    public UIAddCommandUtils(UIAddOperationUtils utilsOperation) 
    {
        this.utilsOperation = utilsOperation;
    }

    public UIAddCommandUtils() {
    }

    public UIAddOperationUtils getUtilsOperation() {
        return utilsOperation;
    }

    public void setUtilsOperation(UIAddOperationUtils utilsOperation) {
        this.utilsOperation = utilsOperation;
    }
    
    public void testCommand(Command c, JTextArea salida)
    {
        OperationController add = new OperationController(salida, new AnalizerController(), new JTable());
        System.out.println("El comando a ser probado es: "+c.getCommand());
        add.setCommand(c);
        add.setSalida(salida);
        add.testOperation(c);
    }
    
    public void addCommand(String comm )
    {
        this.command = new Command();
        command.setCommand(comm);
        System.out.println("La coleccion de politicas a asignar al comando tiene "+politics.size()+" elementos");
        command.setPolitics(politics);
        this.utilsOperation.addCommand(command);
//        this.politics.clear();
//        command.set
    }

    public void setValues(Collection<TrueValue> values) {
        this.values = values;
        System.out.println("Se agrego una coleccion de valores a la politica");
    }
    
    public void newPolitic(String sentence, String objetive, int positionObjetive, String name)
    {
        System.out.println("La oracion es: "+sentence);
        
        this.politic = new Politic();
        politic.setSentence(sentence);
        politic.setObjetive(objetive);
        politic.setInitString(sentence.substring(0,(positionObjetive-1)));
        positionObjetive = positionObjetive + objetive.length();
        politic.setEndString(sentence.substring(positionObjetive,sentence.length()));
        
        System.out.println("El objetivo a evaluar es: "+objetive);
        System.out.println("La cadena inicial es: "+politic.getInitString());
        System.out.println("La cadena final es: "+politic.getEndString());
        System.out.println("La politica tiene "+values.size()+" valores verdaderos");
        politic.setTrueValues(values);
        politic.setName(name);
        this.politics.add(politic);
//        this.values.clear();
    }
    
}
